import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store/index.js'
Vue.use(Router)

const router = new Router({
	routes: [{
			path: '/index',
			redirect: '/',
		},
		{
			path: '/',
			name: 'index',
			component: (resolve) => {
				require(['@/views/Index'], resolve)
			},
			meta: {
				title: '首页',
				isShowHead: false,
				isShowFoot: true,
				isShowBack: false
			}
		},
		{
			path: '/shop',
			name: 'shop',
			component: (resolve) => {
				require(['@/views/Shop'], resolve)
			},
			meta: {
				title: '商场',
				isShowHead: false,
				isShowFoot: true,
				isShowBack: false
			}
		},
		{
			path: '/mine',
			name: 'mine',
			component: (resolve) => {
				require(['@/views/Mine'], resolve)
			},
			meta: {
				title: '我的',
				isShowHead: true,
				isShowFoot: true,
				isShowBack: false
			}
		},
		{
			path: '/setting',
			name: 'setting',
			component: (resolve) => {
				require(['@/views/Setting'], resolve)
			},
			meta: {
				title: '换肤',
				isShowHead: true,
				isShowFoot: false,
				isShowBack: true
			}
		},
		{
			path: '/login',
			name: 'login',
			component: (resolve) => {
				require(['@/views/Login'], resolve)
			},
			meta: {
				title: '登录',
				isShowHead: true,
				isShowFoot: false,
				isShowBack: true
			}
		},
		{
			path: '/cart',
			name: 'cart',
			component: (resolve) => {
				require(['@/views/Cart'], resolve)
			},
			meta: {
				title: '购物车列表',
				isShowHead: true,
				isShowFoot: false,
				isShowBack: true
			}
		},
		{
			path: '/pro_detail',
			name: 'pro_detail',
			component: (resolve) => {
				require(['@/views/proDetail'], resolve)
			},
			meta: {
				title: '商品详情',
				isShowHead: true,
				isShowFoot: false,
				isShowBack: true
			}
		},
		{
			path: '/category',
			name: 'category',
			component: (resolve) => {
				require(['@/views/Category'], resolve)
			},
			meta: {
				title: '分类',
				isShowHead: false,
				isShowFoot: true,
				isShowBack: false
			}
		},
		{
			path: '/searchcook',
			name: 'searchcook',
			component: (resolve) => {
				require(['@/views/searchCook'], resolve)
			},
			meta: {
				title: '学做菜',
				isShowHead: true,
				isShowFoot: false,
				isShowBack: true
			}
		},
		{
			path: '/cook',
			name: 'cook',
			component: (resolve) => {
				require(['@/views/Cook'], resolve)
			},
			meta: {
				title: '学做菜',
				isShowHead: true,
				isShowFoot: false,
				isShowBack: true
			}
		},
		{
			path: '/order',
			name: 'order',
			component: (resolve) => {
				require(['@/views/Order'], resolve)
			},
			meta: {
				title: '订单结算',
				isShowHead: true,
				isShowFoot: false,
				isShowBack: true
			}
		}

	]
})
router.afterEach(function(to, from) {
	var toL = to.path.split('/').length;
	var fromL = from.path.split('/').length;
	if (to.meta.title) {
		store.dispatch("updateNavbarTitle", to.meta.title);
		store.dispatch('updateNavbarStatus', {
			isShowHead: to.meta.isShowHead,
			isShowFoot: to.meta.isShowFoot,
			isShowBack: to.meta.isShowBack
		})
		document.title = "食鲜-" + to.meta.title || "";
	}
})
export default router;
